package LeetCode.leetcode617;

public class Review1 {
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        TreeNode node;
        if (root1 == null && root2 == null) return null;
        else if (root1 != null && root2 != null){
            node = new TreeNode(root1.val + root2.val);
            node.left = mergeTrees(root1.left,root2.left);
            node.right = mergeTrees(root1.right,root2.right);
        }else {
            if (root1 == null){
                node =  new TreeNode(root2.val);
                node.left =mergeTrees(null,root2.left);
                node.right = mergeTrees(null,root2.right);
            }else {
                node =  new TreeNode(root1.val);
                node.left = mergeTrees(root1.left,null);
                node.right = mergeTrees(root1.right,null);
            }
        }
        return node;
    }
}
